/**
 * 编辑-js
 */
var vm = new Vue({
	el:'#dpLTE',
	data: {
		liveXcxCourses: {
			id: 0,
            //0：不单卖  1：可以单卖
            singlesold:0,
            activities:0,
            recommend:1,
            focus:0,
            duration:0,
            series:0,
            activitiesfee:null,
            liveparenttype:null,
            seriesid:null,
            cover:null,
// *活动设置：无活动(默认)、有活动(选中后显示“活动价”输入框)
// *首页焦点：否(默认)、是
// *首页推荐：否、是(默认)
		},

        liveparenttypes:[],
        livetypes:[],
        seriesList:[],//获取系列课列表
        livetype:null,
        series:{
            title:null,
        },
        ue:UE.getEditor('liveXcxCourses-content')
	},
    watch: {
        "liveXcxCourses.liveparenttype": function (val, oldval) {
            if (val !== oldval) {
                var _vm = this;
                if(_vm){
                    Utils.getLiveRoomTypes({
                        pid: val,
                        serviceType:'getSon',
                        success: function (result) {
                            _vm.livetypes = result.rows;
                        }
                    });
                }
            }
        },
        "liveXcxCourses.activities":function (val, oldval) {
            if (val !== oldval) {
                //切换到加密时，清楚价格信息
                if(val!=1) vm.liveXcxCourses.activitiesfee = null;
            }
        },
        "liveXcxCourses.series":function (val, oldval) {
            if (val !== oldval) {
                //切换清除信息
                if(val!=1) {
                    vm.liveXcxCourses.seriesid = null;
                    vm.series.title = null;
                }
            }
        }
    },
	methods : {
		setForm: function() {
			$.SetForm({
				url: '../../srblive/courses/info?_' + $.now(),
		    	param: vm.liveXcxCourses.id,
		    	success: function(data) {
		    		vm.liveXcxCourses = data.liveXcxCourses;
                    vm.livetype = vm.liveXcxCourses.livetype;
                    if(data.series){
                        vm.series = data.series;
                    }
                    $('#liveXcxCourses-sourceurl').attr("src",vm.liveXcxCourses.sourceurl);

                    //富文本-赋值
                    vm.ue.setContent(htmlDecodeByRegExp(vm.liveXcxCourses.content),false);
		    	}
			});
		},
		acceptClick: function() {
			if (!$('#form').Validform()) {
		        return false;
		    }

            //富文本-取值
            vm.liveXcxCourses.content = htmlEncodeByRegExp(vm.ue.getContent());

		    $.ConfirmForm({
		    	url: '../../srblive/courses/update?_' + $.now(),
		    	param: vm.liveXcxCourses,
		    	success: function(data) {
		    		$.currentIframe().vm.load();
		    	}
		    });
		},
        seriesListDlg:function () {
            dialogOpen({
                id : 'seriesListDlg',
                title: '选择系列课',
                url: 'srblive_html/courses/listForDlg.html?&_' + $.now(),
                width: '70%',
                height: '90%',
                btnAlign: 'r',
                btn: ['选中此系列课','取消'],
                success: function (iframeId) {
                },
                yes: function (iframeId) {
                    top.frames[iframeId].vm.acceptClick('layerForm');
                }
            });
        }
	},
    beforeCreate:function () {
        //初始化父类型
        Utils.getLiveRoomTypes({
            success:function (result) {
                vm.liveparenttypes = result.rows;
            }
        });

        // //获取获取系列课列表
        // $.getJSON('../../srblive/courses/getSeriesList?_' + $.now(), function(r) {
        //     vm.seriesList = r.rows;
        // });
    },
    mounted:function () {
        var vm = this;

        //延时绑定辖区的下拉选项，为了辖区下拉数据先加载
        setTimeout(function() {
            vm.liveXcxCourses.livetype = vm.livetype; //延时绑定辖区的下拉选项，为了辖区下拉数据先加载
            $('#liveXcxCourses-sourceurl').load();
        },500);
            AjaxUploadUtils.cloudInit({
            targetId:'cover',
            success:function(file, r){
                vm.liveXcxCourses.cover = r.url;
                $('#liveXcxCourses-cover').attr('src',r.url);
                $('#liveXcxCourses-cover').css({
                    height: "148.5px",
                    width:"138.5px",
                });
                $('#liveXcxCourses-cover-td').load();
            },
            extension:/^(jpg|jpeg|png|gif)$/,
            extensionMsg:'只支持jpg、png、gif格式的图片！',
        });
        var AUDIO = document.getElementById('liveXcxCourses-sourceurl');
        //音频上传
        AjaxUploadUtils.cloudInit({
            targetId:'sourceurl',
            success:function(file, r){
                vm.liveXcxCourses.sourceurl = r.url;
                $('#liveXcxCourses-sourceurl').attr("src",r.url);
                $('#liveXcxCourses-sourceurl').load();
                AUDIO.addEventListener('loadeddata', function(){
                    var second = Math.floor(AUDIO.duration)
                    vm.liveXcxCourses.duration = second;
                }, false)
            },
            extension:/^(mp3|wav|ogg|mp4|webm)$/,
            extensionMsg:'只支持mp3、wav、ogg、mp4、webm 格式的音视频！',
        });
    },


})
